package Web.Demo11;

import Web.Demo12.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import static Web.JdbcUtils.JdbcUtils.getDataSource;

public class Loigndao {
    public User login(String username, String password) {
        User user=null;
        try {
            //完成跟数据库的交互
            JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());
          //编写sql语句
            String sql="select * from user2 where username=? and password=?";
            user=jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(User.class),username,password);
        }catch (Exception e){
                    e.printStackTrace();
        }

        return user;
    }
}
